<script setup lang="ts">
import {reqHospitalLevelAndRegion} from '@/api/home'
import {onMounted,ref} from "vue";
import type {HospitalLevelAndRegionArr, HospitalLevelAndRegionResponseData} from "@/api/home/type.ts";

//存储地区数据
let regionArr = ref<HospitalLevelAndRegionArr>([]);
let activeFlag = ref<String>('');

onMounted(()=>{
  getRegion();
})

//获取地区数据
const getRegion = async () => {
  let result:HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion("Beijin");
  if(result.code == 200){
    regionArr.value = result.data;
  }
}

//点击等级的按钮回调
const changeRegion = (region:String) =>{
  activeFlag.value = region;
  $emit("getRegion",region);
}

const $emit = defineEmits(["getRegion"]);
</script>

<template>
  <div class="region">
    <div class="content">
      <div class="left">地区：</div>
      <ul>
        <li :class="{active:activeFlag==''}" @click="changeRegion('')" >全部</li>
        <li v-for="item in regionArr" :class="{active:activeFlag==item.value}" :key="item.value" @click="changeRegion(item.value)">{{item.name}}</li>
      </ul>
    </div>
  </div>
</template>

<style scoped lang="scss">
.region{
  color: #7f7f7f;
  margin-top: 10px;
  .content{
    display: flex;
    .left{
      margin-right: 10px;
      //width: 60px;
      white-space: nowrap;
    }
    ul{
      display: flex;
      flex-wrap: wrap;
      li{
        margin-right: 5px;
        margin-bottom: 10px;
        &.active{
          color:#55a6fe;
        }
      }
      li:hover{
        color: #55a6fe;
      }
    }
  }
}
</style>
